package com.getinstaliker.httptask;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.content.Context;

import com.getinstaliker.httptask.model.MediaIdModel;
import com.getinstaliker.httptask.model.ResultModel;
import com.getinstaliker.httptask.model.UpdateLikeModel;
import com.getinstaliker.httptask.model.UserInfoModel;
import com.getinstaliker.instagram.InstagramBaseTask;

/**
 * The Class GetInstalikerTask.
 * @author HuanND
 */
public class GetInstalikerTask extends InstagramBaseTask{

	/** The Constant ACCESS_TOKEN_PARAM. */
	private static final String ACCESS_TOKEN_PARAM = "access_token";
	
	/** The Constant MEDIA_ID_PARAM. */
	private static final String MEDIA_ID_PARAM = "media_id";
	
	/** The Constant LIKE_NEEDED_PARAM. */
	private static final String LIKE_NEEDED_PARAM = "like_needed";
	
	/** The Constant TIME_PARAM. */
	private static final String TIME_PARAM = "time";
	/**
	 * Adds the user.
	 *
	 * @param context the context
	 * @param accessToken the access token
	 * @param listener the listener
	 */
	public static void addUser(Context context,String accessToken,final InstagramTaskListener<ResultModel> listener){
		List<NameValuePair> mPairs = new ArrayList<NameValuePair>();
		mPairs.add(new BasicNameValuePair(ACCESS_TOKEN_PARAM, accessToken));
		executeHttpPostTask(context, GetInstalikerApi.ADD_USER_API, mPairs, listener, ResultModel.class);
	}
	
	
	/**
	 * Gets the media id task.
	 *
	 * @param context the context
	 * @param accessToken the access token
	 * @param listener the listener
	 * @return the media id task
	 */
	public static void getMediaIdTask(Context context,String accessToken,final InstagramTaskListener<MediaIdModel> listener){
		String url = GetInstalikerApi.GET_MEDIA_ID_API+"?access_token="+accessToken;
		executeHttpGetTask(context, url, listener, MediaIdModel.class);
	}
	
	/**
	 * Update like sucess task.
	 *
	 * @param context the context
	 * @param model the model
	 * @param accessToken the access token
	 * @param listener the listener
	 */
	public static void updateLikeSucessTask(Context context,MediaIdModel model,String accessToken,final InstagramTaskListener<UpdateLikeModel> listener){
		List<NameValuePair> mPairs = new ArrayList<NameValuePair>();
		mPairs.add(new BasicNameValuePair(ACCESS_TOKEN_PARAM, accessToken));
		mPairs.add(new BasicNameValuePair(MEDIA_ID_PARAM, model.data.media_id));
		mPairs.add(new BasicNameValuePair(LIKE_NEEDED_PARAM, model.data.like_needed));
		mPairs.add(new BasicNameValuePair(TIME_PARAM, model.data.time));
		executeHttpPostTask(context, GetInstalikerApi.UPDATE_LIKE_SUCCESS_API, mPairs, listener, UpdateLikeModel.class);
	}
	
	/**
	 * Gets the user info.
	 *
	 * @param context the context
	 * @param accessToken the access token
	 * @param listener the listener
	 * @return the user info
	 */
	public static void getUserInfo(Context context,String accessToken,final InstagramTaskListener<UserInfoModel> listener){
		String url = GetInstalikerApi.USER_INFO_API+"?access_token="+accessToken;
		executeHttpGetTask(context, url, listener, UserInfoModel.class);
	}
	
	/**
	 * Spend coins task.
	 *
	 * @param context the context
	 * @param accessToken the access token
	 * @param like_needed the like_needed
	 * @param media_id the media_id
	 * @param listener the listener
	 */
	public static void SpendCoinsTask(Context context,String accessToken,String like_needed,String media_id,final InstagramTaskListener<ResultModel> listener){
		List<NameValuePair> mPairs = new ArrayList<NameValuePair>();
		mPairs.add(new BasicNameValuePair(ACCESS_TOKEN_PARAM, accessToken));
		mPairs.add(new BasicNameValuePair(MEDIA_ID_PARAM, media_id));
		mPairs.add(new BasicNameValuePair(LIKE_NEEDED_PARAM, like_needed));
		executeHttpPostTask(context, GetInstalikerApi.SPEND_API, mPairs, listener, ResultModel.class);
	}
	
}
